export default {
	data() {
		return {
			listData: [],
			listParams: {
				page: 0,
				limit: 15
			},
			listStatus: ''
		}
	},
	methods: {
		getList(params = {}, refresh = false) {
			if (!this.GetListFn) return
			if (!refresh && this.listStatus === 'loading') return
			this.listStatus = 'loading'
			if (refresh) {
				this.listOver = false
				this.listParams.page = 0
			}
			this.listParams.page++
			this.listParams = Object.assign(this.listParams, params)

			// 额外附加的参数
			if (this.getParams) {
				const params = this.getParams()
				this.listParams = Object.assign(this.listParams, params)
			}

			const flag = this.beforeGetList(this.listParams)
			if (!flag) {
				this.listStatus = 'more'
				return
			}
			this.GetListFn(this.listParams).then(res => {
				if (this.listParams.page === 1) {
					this.listData = []
				}
				this.listData = this.listData.concat(res.list)
				// this.listData = res.list.slice(0, 2)
				if (res.hasOwnProperty('lastPage')) {
					this.listStatus = res.lastPage ? 'noMore' : 'more'
				} else {
					this.listStatus = res.list.length === 0 ? 'noMore' : 'more'
				}
				// 列表数据获取完成后回调
				if (this.getListCallback) {
					this.getListCallback(res)
				}
			}).catch(() => {
				this.listStatus = 'more'
			})
		},

		getParams() {
			return {}
		},

		beforeGetList() {
			return true
		}
	}
}
